package application.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspWriter;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import application.models.Modwineorders;

import library.Controller;

/**
 * Servlet implementation class order
 */
public class order extends Controller {
	private static final long serialVersionUID = 1L;
    
	@SuppressWarnings("unchecked")
	public void show(HttpServletRequest request, HttpServletResponse response, JspWriter out) throws ServletException, IOException{
		String name = this.getClass().getSimpleName();
		if(request.getSession().getAttribute("user")!= null) {
			//Prepare Session
			SessionFactory sessionFactory = new Configuration()
				.configure()
				.buildSessionFactory();
			//Start session
			Session session = sessionFactory.openSession();
			session.beginTransaction();
			

			List<Modwineorders> orders = (List<Modwineorders>) session.createQuery("from Modwineorders").list();
			request.setAttribute("orders", orders);
			
			out.flush();
			include(request,response,"/layout/"+name+"/show.jsp");
			
			session.getTransaction().commit();
			session.close();
		}else {
			response.sendRedirect("administrator?op=login");
		}	
	}
}
